package org.example.config.conditional.test.listener;

import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationListener;
import org.springframework.context.event.ContextRefreshedEvent;
import org.springframework.stereotype.Component;

import java.util.Arrays;
import java.util.stream.Collectors;

@Component
public class ApplicationLoadedListener implements ApplicationListener<ContextRefreshedEvent> {
    @Override
    public void onApplicationEvent(ContextRefreshedEvent applicationEvent) {
        ApplicationContext ctx = applicationEvent.getApplicationContext();
        String[] beanDefinitions = ctx.getBeanDefinitionNames();
        String beans = Arrays.stream(beanDefinitions).filter(beanName -> beanName.indexOf("mockUser") >= 0).collect(Collectors.joining("\n"));
        System.out.println(beans);
    }
}
